package com.corner.testPackage;

import com.corner.CornerApplication;
import com.corner.system.domain.GzhUserinfo;
import com.corner.system.domain.vo.MenuDetailsVo;
import com.corner.system.domain.vo.MenuVo;
import com.corner.system.service.WxgzhService;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;

/**
 * @program: corner-admin
 * @description:
 * @author: lydms
 * @create: 2022-12-30 12:43
 **/

@SpringBootTest(classes= CornerApplication.class)
@RunWith(SpringRunner.class)
public class mtest {

    @Autowired
    private WxgzhService wxgzhService;
    @Autowired
    private RestTemplate restTemplate;

    @Value("${GZH_APPID}")
    public String gzh_appid;
    @Value("${GZH_SECRET}")
    public String gzh_secret;

    @Test
    public void a(){
        String accessToken = wxgzhService.getAccessToken();
        System.out.println("哎呀妈呀哎呀妈呀哎呀妈呀哎呀妈呀accessToken："+accessToken);
        //String accessTokenUrl = wxgzhService.getUrlAccessToken();
        //System.out.println("哎呀妈呀哎呀妈呀哎呀妈呀哎呀妈呀accessTokenUrl："+accessToken);

    }

    @Test
    public void b(){
        try {
            //String encode = URLEncoder.encode("1.62.163.250:8084/#/login", "UTF-8");
            String encode1 = URLEncoder.encode("#/changeTelNew", "UTF-8");
            System.out.println("编码后url:"+encode1);
            String encode2 = URLEncoder.encode("#/myOperationList", "UTF-8");
            System.out.println("编码后url:"+encode2);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }


    @Test
    public void createMenu()throws Exception{
        String accessToken = wxgzhService.getAccessToken();
        System.out.println(accessToken);
        String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+accessToken;
        String myDeviceEncode = URLEncoder.encode("#/myDevice", "UTF-8");
        String userCenterEncode = URLEncoder.encode("#/userCenter", "UTF-8");
        String editInfoEncode = URLEncoder.encode("#/editInfo", "UTF-8");

        // 要发送的数据对象
        MenuVo menuVo = new MenuVo();
        MenuDetailsVo detailsVo1 = new MenuDetailsVo();
        detailsVo1.setName("用户登录");
        detailsVo1.setType("view");
        detailsVo1.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+gzh_appid+"&redirect_uri=http://www.wushuizhili.cn/&response_type=code&scope=snsapi_base&state=loginsuccess#wechat_redirect");

        MenuDetailsVo detailsVo2 = new MenuDetailsVo();
        detailsVo2.setName("领取补贴");
        detailsVo2.setType("view");
        detailsVo2.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+gzh_appid+"&redirect_uri=http://www.wushuizhili.cn/"+myDeviceEncode+"&response_type=code&scope=snsapi_base&state=123#wechat_redirect");


        MenuDetailsVo detailsVo30 = new MenuDetailsVo();
        detailsVo30.setName("用户中心");
        detailsVo30.setType("view");
        detailsVo30.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+gzh_appid+"&redirect_uri=http://www.wushuizhili.cn/"+userCenterEncode+"&response_type=code&scope=snsapi_base&state=123#wechat_redirect");

      /*  MenuDetailsVo detailsVo31 = new MenuDetailsVo();
        detailsVo31.setName("修改信息");
        detailsVo31.setType("view");
        detailsVo31.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7ebdabb02e6faa33&redirect_uri=http://www.wushuizhili.cn/#/editBaseInfo&response_type=code&scope=snsapi_base&state=123#wechat_redirect");

        MenuDetailsVo detailsVo32 = new MenuDetailsVo();
        detailsVo32.setName("申请服务");
        detailsVo32.setType("view");
        detailsVo32.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7ebdabb02e6faa33&redirect_uri=http://www.wushuizhili.cn/#/applyServe&response_type=code&scope=snsapi_base&state=123#wechat_redirect");
*/
        MenuDetailsVo detailsVo32 = new MenuDetailsVo();
        detailsVo32.setName("申请服务");
        detailsVo32.setType("view");
        detailsVo32.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid="+gzh_appid+"&redirect_uri=http://www.wushuizhili.cn/"+editInfoEncode+"&response_type=code&scope=snsapi_base&state=123#wechat_redirect");

        MenuDetailsVo detailsVo33 = new MenuDetailsVo();
        detailsVo33.setName("联系我们");
        detailsVo33.setType("click");
        detailsVo33.setKey("CONTACT_US");

        List ylist = new ArrayList<>();
        ylist.add(detailsVo30);
//        ylist.add(detailsVo31);
        ylist.add(detailsVo32);
        ylist.add(detailsVo33);

        MenuDetailsVo detailsVo3 = new MenuDetailsVo();
        detailsVo3.setName("用户中心");
        detailsVo3.setSub_button(ylist);


        List<MenuDetailsVo> list = new ArrayList<MenuDetailsVo>();
        list.add(detailsVo1);
        list.add(detailsVo2);
        list.add(detailsVo3);
        menuVo.setButton(list);
        System.out.println(menuVo);


        // 发送post请求，并输出结果
        Object o = restTemplate.postForObject(url, menuVo, Object.class);
        System.out.println(o);
    }




    public static void main(String[] args) {
        MenuVo menuVo = new MenuVo();
        MenuDetailsVo detailsVo1 = new MenuDetailsVo();
        detailsVo1.setName("用户绑定");
        detailsVo1.setType("view");
        detailsVo1.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7ebdabb02e6faa33&redirect_uri=http://www.wushuizhili.cn/&response_type=code&scope=snsapi_base&state=loginsuccess#wechat_redirect");

        MenuDetailsVo detailsVo2 = new MenuDetailsVo();
        detailsVo2.setName("领取补贴");
        detailsVo2.setType("view");
        detailsVo2.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7ebdabb02e6faa33&redirect_uri=http://www.wushuizhili.cn/myDevice&response_type=code&scope=snsapi_base&state=123#wechat_redirect");


        MenuDetailsVo detailsVo30 = new MenuDetailsVo();
        detailsVo30.setName("用户中心");
        detailsVo30.setType("view");
        detailsVo30.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7ebdabb02e6faa33&redirect_uri=http://www.wushuizhili.cn/userCenter&response_type=code&scope=snsapi_base&state=123#wechat_redirect");

        MenuDetailsVo detailsVo31 = new MenuDetailsVo();
        detailsVo31.setName("修改信息");
        detailsVo31.setType("view");
        detailsVo31.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7ebdabb02e6faa33&redirect_uri=http://www.wushuizhili.cn/editBaseInfo&response_type=code&scope=snsapi_base&state=123#wechat_redirect");

        MenuDetailsVo detailsVo32 = new MenuDetailsVo();
        detailsVo32.setName("申请服务");
        detailsVo32.setType("view");
        detailsVo31.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7ebdabb02e6faa33&redirect_uri=http://www.wushuizhili.cn/applyServe&response_type=code&scope=snsapi_base&state=123#wechat_redirect");

        MenuDetailsVo detailsVo33 = new MenuDetailsVo();
        detailsVo33.setName("联系我们");
        detailsVo33.setType("click");
        detailsVo33.setKey("CONTACT_US");

        List ylist = new ArrayList<>();
        ylist.add(detailsVo30);
        ylist.add(detailsVo31);
        ylist.add(detailsVo32);
        ylist.add(detailsVo33);

        MenuDetailsVo detailsVo3 = new MenuDetailsVo();
        detailsVo3.setName("用户中心");
        detailsVo3.setSub_button(ylist);


        List<MenuDetailsVo> list = new ArrayList<MenuDetailsVo>();
        list.add(detailsVo1);
        list.add(detailsVo2);
        list.add(detailsVo3);
        menuVo.setButton(list);
        System.out.println(menuVo);
    }

}
